<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE NoImplicitPrelude #-}</span><span>
</span><span id="line-3"></span><span class="hs-pragma">{-# OPTIONS_GHC -funbox-strict-fields #-}</span><span>
</span><span id="line-4"></span><span>
</span><span id="line-5"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- Module      :  GHC.IO.BufferedIO</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow 2008</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- License     :  see libraries/base/LICENSE</span><span>
</span><span id="line-10"></span><span class="hs-comment">--</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Maintainer  :  cvs-ghc@haskell.org</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Stability   :  internal</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- Portability :  non-portable (GHC Extensions)</span><span>
</span><span id="line-14"></span><span class="hs-comment">--</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- Class of buffered IO devices</span><span>
</span><span id="line-16"></span><span class="hs-comment">--</span><span>
</span><span id="line-17"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-18"></span><span>
</span><span id="line-19"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.IO.BufferedIO</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-20"></span><span>        </span><span class="annot"><a href="GHC.IO.BufferedIO.html#BufferedIO"><span class="hs-identifier">BufferedIO</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-21"></span><span>        </span><span class="annot"><a href="GHC.IO.BufferedIO.html#readBuf"><span class="hs-identifier">readBuf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.BufferedIO.html#readBufNonBlocking"><span class="hs-identifier">readBufNonBlocking</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.BufferedIO.html#writeBuf"><span class="hs-identifier">writeBuf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.BufferedIO.html#writeBufNonBlocking"><span class="hs-identifier">writeBufNonBlocking</span></a></span><span>
</span><span id="line-22"></span><span>    </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-23"></span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-25"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Ptr.html"><span class="hs-identifier">GHC.Ptr</span></a></span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Word.html"><span class="hs-identifier">Data.Word</span></a></span><span>
</span><span id="line-27"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Num.html"><span class="hs-identifier">GHC.Num</span></a></span><span>
</span><span id="line-28"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Device.html"><span class="hs-identifier">GHC.IO.Device</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">IODevice</span></span><span>
</span><span id="line-29"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Device.html"><span class="hs-identifier">GHC.IO.Device</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">RawIO</span></span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html"><span class="hs-identifier">GHC.IO.Buffer</span></a></span><span>
</span><span id="line-31"></span><span>
</span><span id="line-32"></span><span class="hs-comment">-- | The purpose of 'BufferedIO' is to provide a common interface for I/O</span><span>
</span><span id="line-33"></span><span class="hs-comment">-- devices that can read and write data through a buffer.  Devices that</span><span>
</span><span id="line-34"></span><span class="hs-comment">-- implement 'BufferedIO' include ordinary files, memory-mapped files,</span><span>
</span><span id="line-35"></span><span class="hs-comment">-- and bytestrings.  The underlying device implementing a 'System.IO.Handle'</span><span>
</span><span id="line-36"></span><span class="hs-comment">-- must provide 'BufferedIO'.</span><span>
</span><span id="line-37"></span><span class="hs-comment">--</span><span>
</span><span id="line-38"></span><span class="hs-keyword">class</span><span> </span><span id="BufferedIO"><span class="annot"><a href="GHC.IO.BufferedIO.html#BufferedIO"><span class="hs-identifier hs-var">BufferedIO</span></a></span></span><span> </span><span id="local-6989586621679536094"><span class="annot"><a href="#local-6989586621679536094"><span class="hs-identifier hs-type">dev</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-39"></span><span>  </span><span class="hs-comment">-- | allocate a new buffer.  The size of the buffer is at the</span><span>
</span><span id="line-40"></span><span>  </span><span class="hs-comment">-- discretion of the device; e.g. for a memory-mapped file the</span><span>
</span><span id="line-41"></span><span>  </span><span class="hs-comment">-- buffer will probably cover the entire file.</span><span>
</span><span id="line-42"></span><span>  </span><span id="newBuffer"><span class="annot"><a href="GHC.IO.BufferedIO.html#newBuffer"><span class="hs-identifier hs-type">newBuffer</span></a></span></span><span>         </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679536094"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#BufferState"><span class="hs-identifier hs-type">BufferState</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-43"></span><span>
</span><span id="line-44"></span><span>  </span><span class="hs-comment">-- | reads bytes into the buffer, blocking if there are no bytes</span><span>
</span><span id="line-45"></span><span>  </span><span class="hs-comment">-- available.  Returns the number of bytes read (zero indicates</span><span>
</span><span id="line-46"></span><span>  </span><span class="hs-comment">-- end-of-file), and the new buffer.</span><span>
</span><span id="line-47"></span><span>  </span><span id="fillReadBuffer"><span class="annot"><a href="GHC.IO.BufferedIO.html#fillReadBuffer"><span class="hs-identifier hs-type">fillReadBuffer</span></a></span></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679536094"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-48"></span><span>
</span><span id="line-49"></span><span>  </span><span class="hs-comment">-- | reads bytes into the buffer without blocking.  Returns the</span><span>
</span><span id="line-50"></span><span>  </span><span class="hs-comment">-- number of bytes read (Nothing indicates end-of-file), and the new</span><span>
</span><span id="line-51"></span><span>  </span><span class="hs-comment">-- buffer.</span><span>
</span><span id="line-52"></span><span>  </span><span id="fillReadBuffer0"><span class="annot"><a href="GHC.IO.BufferedIO.html#fillReadBuffer0"><span class="hs-identifier hs-type">fillReadBuffer0</span></a></span></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679536094"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-53"></span><span>
</span><span id="line-54"></span><span>  </span><span class="hs-comment">-- | Prepares an empty write buffer.  This lets the device decide</span><span>
</span><span id="line-55"></span><span>  </span><span class="hs-comment">-- how to set up a write buffer: the buffer may need to point to a</span><span>
</span><span id="line-56"></span><span>  </span><span class="hs-comment">-- specific location in memory, for example.  This is typically used</span><span>
</span><span id="line-57"></span><span>  </span><span class="hs-comment">-- by the client when switching from reading to writing on a</span><span>
</span><span id="line-58"></span><span>  </span><span class="hs-comment">-- buffered read/write device.</span><span>
</span><span id="line-59"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-60"></span><span>  </span><span class="hs-comment">-- There is no corresponding operation for read buffers, because before</span><span>
</span><span id="line-61"></span><span>  </span><span class="hs-comment">-- reading the client will always call 'fillReadBuffer'.</span><span>
</span><span id="line-62"></span><span>  </span><span id="emptyWriteBuffer"><span class="annot"><a href="GHC.IO.BufferedIO.html#emptyWriteBuffer"><span class="hs-identifier hs-type">emptyWriteBuffer</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679536094"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-63"></span><span>  </span><span id="local-6989586621679536058"><span class="annot"><a href="GHC.IO.BufferedIO.html#emptyWriteBuffer"><span class="hs-identifier hs-var hs-var">emptyWriteBuffer</span></a></span><span> </span><span id="local-6989586621679536055"><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679536055"><span class="hs-identifier hs-var">_dev</span></a></span></span><span> </span><span id="local-6989586621679536054"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536054"><span class="hs-identifier hs-var">buf</span></a></span></span><span>
</span><span id="line-64"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; IO (Buffer Word8)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536054"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufState :: BufferState
</span><a href="#local-6989586621679536051"><span class="hs-identifier hs-var">bufState</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#WriteBuffer"><span class="hs-identifier hs-var">WriteBuffer</span></a></span><span> </span><span class="hs-special">}</span></span><span>
</span><span id="line-65"></span><span>
</span><span id="line-66"></span><span>  </span><span class="hs-comment">-- | Flush all the data from the supplied write buffer out to the device.</span><span>
</span><span id="line-67"></span><span>  </span><span class="hs-comment">-- The returned buffer should be empty, and ready for writing.</span><span>
</span><span id="line-68"></span><span>  </span><span id="flushWriteBuffer"><span class="annot"><a href="GHC.IO.BufferedIO.html#flushWriteBuffer"><span class="hs-identifier hs-type">flushWriteBuffer</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679536094"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-69"></span><span>
</span><span id="line-70"></span><span>  </span><span class="hs-comment">-- | Flush data from the supplied write buffer out to the device</span><span>
</span><span id="line-71"></span><span>  </span><span class="hs-comment">-- without blocking.  Returns the number of bytes written and the</span><span>
</span><span id="line-72"></span><span>  </span><span class="hs-comment">-- remaining buffer.</span><span>
</span><span id="line-73"></span><span>  </span><span id="flushWriteBuffer0"><span class="annot"><a href="GHC.IO.BufferedIO.html#flushWriteBuffer0"><span class="hs-identifier hs-type">flushWriteBuffer0</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679536094"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-74"></span><span>
</span><span id="line-75"></span><span class="hs-comment">-- for an I/O device, these operations will perform reading/writing</span><span>
</span><span id="line-76"></span><span class="hs-comment">-- to/from the device.</span><span>
</span><span id="line-77"></span><span>
</span><span id="line-78"></span><span class="hs-comment">-- for a memory-mapped file, the buffer will be the whole file in</span><span>
</span><span id="line-79"></span><span class="hs-comment">-- memory.  fillReadBuffer sets the pointers to encompass the whole</span><span>
</span><span id="line-80"></span><span class="hs-comment">-- file, and flushWriteBuffer needs to do no I/O.  A memory-mapped</span><span>
</span><span id="line-81"></span><span class="hs-comment">-- file has to maintain its own file pointer.</span><span>
</span><span id="line-82"></span><span>
</span><span id="line-83"></span><span class="hs-comment">-- for a bytestring, again the buffer should match the bytestring in</span><span>
</span><span id="line-84"></span><span class="hs-comment">-- memory.</span><span>
</span><span id="line-85"></span><span>
</span><span id="line-86"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-87"></span><span class="hs-comment">-- Low-level read/write to/from buffers</span><span>
</span><span id="line-88"></span><span>
</span><span id="line-89"></span><span class="hs-comment">-- These operations make it easy to implement an instance of 'BufferedIO'</span><span>
</span><span id="line-90"></span><span class="hs-comment">-- for an object that supports 'RawIO'.</span><span>
</span><span id="line-91"></span><span>
</span><span id="line-92"></span><span id="local-6989586621679536088"><span class="annot"><a href="GHC.IO.BufferedIO.html#readBuf"><span class="hs-identifier hs-type">readBuf</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Device.html#RawIO"><span class="hs-identifier hs-type">RawIO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679536088"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679536088"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-93"></span><span id="readBuf"><span class="annot"><span class="annottext">readBuf :: forall dev.
RawIO dev =&gt;
dev -&gt; Buffer Word8 -&gt; IO (Int, Buffer Word8)
</span><a href="GHC.IO.BufferedIO.html#readBuf"><span class="hs-identifier hs-var hs-var">readBuf</span></a></span></span><span> </span><span id="local-6989586621679536041"><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679536041"><span class="hs-identifier hs-var">dev</span></a></span></span><span> </span><span id="local-6989586621679536040"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536040"><span class="hs-identifier hs-var">bbuf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-94"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679536039"><span class="annot"><span class="annottext">bytes :: Int
</span><a href="#local-6989586621679536039"><span class="hs-identifier hs-var hs-var">bytes</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferAvailable"><span class="hs-identifier hs-var">bufferAvailable</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536040"><span class="hs-identifier hs-var">bbuf</span></a></span><span>
</span><span id="line-95"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679536037"><span class="annot"><span class="annottext">offset :: Word64
</span><a href="#local-6989586621679536037"><span class="hs-identifier hs-var hs-var">offset</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Word64
forall e. Buffer e -&gt; Word64
</span><a href="GHC.IO.Buffer.html#bufferOffset"><span class="hs-identifier hs-var">bufferOffset</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536040"><span class="hs-identifier hs-var">bbuf</span></a></span><span>
</span><span id="line-96"></span><span>  </span><span id="local-6989586621679536035"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679536035"><span class="hs-identifier hs-var">res</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; (Ptr Word8 -&gt; IO Int) -&gt; IO Int
forall e a. Buffer e -&gt; (Ptr e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Buffer.html#withBuffer"><span class="hs-identifier hs-var">withBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536040"><span class="hs-identifier hs-var">bbuf</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Word8 -&gt; IO Int) -&gt; IO Int)
-&gt; (Ptr Word8 -&gt; IO Int) -&gt; IO Int
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679536033"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679536033"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-97"></span><span>             </span><span class="annot"><span class="annottext">dev -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO Int
forall a. RawIO a =&gt; a -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Device.html#read"><span class="hs-identifier hs-var">RawIO.read</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679536041"><span class="hs-identifier hs-var">dev</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679536033"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr Word8
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536040"><span class="hs-identifier hs-var">bbuf</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679536037"><span class="hs-identifier hs-var">offset</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679536039"><span class="hs-identifier hs-var">bytes</span></a></span><span>
</span><span id="line-98"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679536030"><span class="annot"><span class="annottext">bbuf' :: Buffer Word8
</span><a href="#local-6989586621679536030"><span class="hs-identifier hs-var hs-var">bbuf'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Buffer Word8 -&gt; Buffer Word8
forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAddOffset"><span class="hs-identifier hs-var">bufferAddOffset</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679536035"><span class="hs-identifier hs-var">res</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536040"><span class="hs-identifier hs-var">bbuf</span></a></span><span>
</span><span id="line-99"></span><span>  </span><span class="annot"><span class="annottext">(Int, Buffer Word8) -&gt; IO (Int, Buffer Word8)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679536035"><span class="hs-identifier hs-var">res</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536030"><span class="hs-identifier hs-var">bbuf'</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536030"><span class="hs-identifier hs-var">bbuf'</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679536035"><span class="hs-identifier hs-var">res</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-100"></span><span>         </span><span class="hs-comment">-- zero indicates end of file</span><span>
</span><span id="line-101"></span><span>
</span><span id="line-102"></span><span id="local-6989586621679536073"><span class="annot"><a href="GHC.IO.BufferedIO.html#readBufNonBlocking"><span class="hs-identifier hs-type">readBufNonBlocking</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Device.html#RawIO"><span class="hs-identifier hs-type">RawIO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679536073"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679536073"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span>
</span><span id="line-103"></span><span>                     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">,</span><span>   </span><span class="hs-comment">-- Nothing ==&gt; end of file</span><span>
</span><span id="line-104"></span><span>                                         </span><span class="hs-comment">-- Just n  ==&gt; n bytes were read (n&gt;=0)</span><span>
</span><span id="line-105"></span><span>                            </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-106"></span><span id="readBufNonBlocking"><span class="annot"><span class="annottext">readBufNonBlocking :: forall dev.
RawIO dev =&gt;
dev -&gt; Buffer Word8 -&gt; IO (Maybe Int, Buffer Word8)
</span><a href="GHC.IO.BufferedIO.html#readBufNonBlocking"><span class="hs-identifier hs-var hs-var">readBufNonBlocking</span></a></span></span><span> </span><span id="local-6989586621679536021"><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679536021"><span class="hs-identifier hs-var">dev</span></a></span></span><span> </span><span id="local-6989586621679536020"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536020"><span class="hs-identifier hs-var">bbuf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-107"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679536019"><span class="annot"><span class="annottext">bytes :: Int
</span><a href="#local-6989586621679536019"><span class="hs-identifier hs-var hs-var">bytes</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferAvailable"><span class="hs-identifier hs-var">bufferAvailable</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536020"><span class="hs-identifier hs-var">bbuf</span></a></span><span>
</span><span id="line-108"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679536018"><span class="annot"><span class="annottext">offset :: Word64
</span><a href="#local-6989586621679536018"><span class="hs-identifier hs-var hs-var">offset</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Word64
forall e. Buffer e -&gt; Word64
</span><a href="GHC.IO.Buffer.html#bufferOffset"><span class="hs-identifier hs-var">bufferOffset</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536020"><span class="hs-identifier hs-var">bbuf</span></a></span><span>
</span><span id="line-109"></span><span>  </span><span id="local-6989586621679536017"><span class="annot"><span class="annottext">Maybe Int
</span><a href="#local-6989586621679536017"><span class="hs-identifier hs-var">res</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; (Ptr Word8 -&gt; IO (Maybe Int)) -&gt; IO (Maybe Int)
forall e a. Buffer e -&gt; (Ptr e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Buffer.html#withBuffer"><span class="hs-identifier hs-var">withBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536020"><span class="hs-identifier hs-var">bbuf</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Word8 -&gt; IO (Maybe Int)) -&gt; IO (Maybe Int))
-&gt; (Ptr Word8 -&gt; IO (Maybe Int)) -&gt; IO (Maybe Int)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679536016"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679536016"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-110"></span><span>           </span><span class="annot"><span class="annottext">dev -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO (Maybe Int)
forall a.
RawIO a =&gt;
a -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO (Maybe Int)
</span><a href="GHC.IO.Device.html#readNonBlocking"><span class="hs-identifier hs-var">IODevice.readNonBlocking</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679536021"><span class="hs-identifier hs-var">dev</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679536016"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr Word8
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536020"><span class="hs-identifier hs-var">bbuf</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679536018"><span class="hs-identifier hs-var">offset</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679536019"><span class="hs-identifier hs-var">bytes</span></a></span><span>
</span><span id="line-111"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe Int
</span><a href="#local-6989586621679536017"><span class="hs-identifier hs-var">res</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-112"></span><span>     </span><span class="annot"><span class="annottext">Maybe Int
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(Maybe Int, Buffer Word8) -&gt; IO (Maybe Int, Buffer Word8)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Int
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536020"><span class="hs-identifier hs-var">bbuf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-113"></span><span>     </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679536014"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679536014"><span class="hs-identifier hs-var">n</span></a></span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679536013"><span class="annot"><span class="annottext">bbuf' :: Buffer Word8
</span><a href="#local-6989586621679536013"><span class="hs-identifier hs-var hs-var">bbuf'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Buffer Word8 -&gt; Buffer Word8
forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAddOffset"><span class="hs-identifier hs-var">bufferAddOffset</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679536014"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536020"><span class="hs-identifier hs-var">bbuf</span></a></span><span>
</span><span id="line-114"></span><span>                   </span><span class="annot"><span class="annottext">(Maybe Int, Buffer Word8) -&gt; IO (Maybe Int, Buffer Word8)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Maybe Int
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679536014"><span class="hs-identifier hs-var">n</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536013"><span class="hs-identifier hs-var">bbuf'</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536013"><span class="hs-identifier hs-var">bbuf'</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679536014"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-115"></span><span>
</span><span id="line-116"></span><span id="local-6989586621679536070"><span class="annot"><a href="GHC.IO.BufferedIO.html#writeBuf"><span class="hs-identifier hs-type">writeBuf</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Device.html#RawIO"><span class="hs-identifier hs-type">RawIO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679536070"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679536070"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-117"></span><span id="writeBuf"><span class="annot"><span class="annottext">writeBuf :: forall dev. RawIO dev =&gt; dev -&gt; Buffer Word8 -&gt; IO (Buffer Word8)
</span><a href="GHC.IO.BufferedIO.html#writeBuf"><span class="hs-identifier hs-var hs-var">writeBuf</span></a></span></span><span> </span><span id="local-6989586621679536008"><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679536008"><span class="hs-identifier hs-var">dev</span></a></span></span><span> </span><span id="local-6989586621679536007"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536007"><span class="hs-identifier hs-var">bbuf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-118"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679536006"><span class="annot"><span class="annottext">bytes :: Int
</span><a href="#local-6989586621679536006"><span class="hs-identifier hs-var hs-var">bytes</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferElems"><span class="hs-identifier hs-var">bufferElems</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536007"><span class="hs-identifier hs-var">bbuf</span></a></span><span>
</span><span id="line-119"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679536004"><span class="annot"><span class="annottext">offset :: Word64
</span><a href="#local-6989586621679536004"><span class="hs-identifier hs-var hs-var">offset</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Word64
forall e. Buffer e -&gt; Word64
</span><a href="GHC.IO.Buffer.html#bufferOffset"><span class="hs-identifier hs-var">bufferOffset</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536007"><span class="hs-identifier hs-var">bbuf</span></a></span><span>
</span><span id="line-120"></span><span>  </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; (Ptr Word8 -&gt; IO ()) -&gt; IO ()
forall e a. Buffer e -&gt; (Ptr e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Buffer.html#withBuffer"><span class="hs-identifier hs-var">withBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536007"><span class="hs-identifier hs-var">bbuf</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Word8 -&gt; IO ()) -&gt; IO ()) -&gt; (Ptr Word8 -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679536003"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679536003"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-121"></span><span>      </span><span class="annot"><span class="annottext">dev -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO ()
forall a. RawIO a =&gt; a -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO ()
</span><a href="GHC.IO.Device.html#write"><span class="hs-identifier hs-var">IODevice.write</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679536008"><span class="hs-identifier hs-var">dev</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679536003"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr Word8
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536007"><span class="hs-identifier hs-var">bbuf</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679536004"><span class="hs-identifier hs-var">offset</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679536006"><span class="hs-identifier hs-var">bytes</span></a></span><span>
</span><span id="line-122"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679536001"><span class="annot"><span class="annottext">bbuf' :: Buffer Word8
</span><a href="#local-6989586621679536001"><span class="hs-identifier hs-var hs-var">bbuf'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Buffer Word8 -&gt; Buffer Word8
forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAddOffset"><span class="hs-identifier hs-var">bufferAddOffset</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679536006"><span class="hs-identifier hs-var">bytes</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536007"><span class="hs-identifier hs-var">bbuf</span></a></span><span>
</span><span id="line-123"></span><span>  </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; IO (Buffer Word8)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679536001"><span class="hs-identifier hs-var">bbuf'</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-124"></span><span>
</span><span id="line-125"></span><span class="hs-comment">-- XXX ToDo</span><span>
</span><span id="line-126"></span><span id="local-6989586621679536000"><span class="annot"><a href="GHC.IO.BufferedIO.html#writeBufNonBlocking"><span class="hs-identifier hs-type">writeBufNonBlocking</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Device.html#RawIO"><span class="hs-identifier hs-type">RawIO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679536000"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679536000"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-127"></span><span id="writeBufNonBlocking"><span class="annot"><span class="annottext">writeBufNonBlocking :: forall dev.
RawIO dev =&gt;
dev -&gt; Buffer Word8 -&gt; IO (Int, Buffer Word8)
</span><a href="GHC.IO.BufferedIO.html#writeBufNonBlocking"><span class="hs-identifier hs-var hs-var">writeBufNonBlocking</span></a></span></span><span> </span><span id="local-6989586621679535994"><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679535994"><span class="hs-identifier hs-var">dev</span></a></span></span><span> </span><span id="local-6989586621679535993"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679535993"><span class="hs-identifier hs-var">bbuf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-128"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679535992"><span class="annot"><span class="annottext">bytes :: Int
</span><a href="#local-6989586621679535992"><span class="hs-identifier hs-var hs-var">bytes</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferElems"><span class="hs-identifier hs-var">bufferElems</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679535993"><span class="hs-identifier hs-var">bbuf</span></a></span><span>
</span><span id="line-129"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679535991"><span class="annot"><span class="annottext">offset :: Word64
</span><a href="#local-6989586621679535991"><span class="hs-identifier hs-var hs-var">offset</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Word64
forall e. Buffer e -&gt; Word64
</span><a href="GHC.IO.Buffer.html#bufferOffset"><span class="hs-identifier hs-var">bufferOffset</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679535993"><span class="hs-identifier hs-var">bbuf</span></a></span><span>
</span><span id="line-130"></span><span>  </span><span id="local-6989586621679535990"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679535990"><span class="hs-identifier hs-var">res</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; (Ptr Word8 -&gt; IO Int) -&gt; IO Int
forall e a. Buffer e -&gt; (Ptr e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Buffer.html#withBuffer"><span class="hs-identifier hs-var">withBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679535993"><span class="hs-identifier hs-var">bbuf</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Word8 -&gt; IO Int) -&gt; IO Int)
-&gt; (Ptr Word8 -&gt; IO Int) -&gt; IO Int
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679535989"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679535989"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-131"></span><span>            </span><span class="annot"><span class="annottext">dev -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO Int
forall a. RawIO a =&gt; a -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Device.html#writeNonBlocking"><span class="hs-identifier hs-var">IODevice.writeNonBlocking</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679535994"><span class="hs-identifier hs-var">dev</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679535989"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr Word8
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679535993"><span class="hs-identifier hs-var">bbuf</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679535991"><span class="hs-identifier hs-var">offset</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679535992"><span class="hs-identifier hs-var">bytes</span></a></span><span>
</span><span id="line-132"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679535987"><span class="annot"><span class="annottext">bbuf' :: Buffer Word8
</span><a href="#local-6989586621679535987"><span class="hs-identifier hs-var hs-var">bbuf'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Buffer Word8 -&gt; Buffer Word8
forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAddOffset"><span class="hs-identifier hs-var">bufferAddOffset</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679535992"><span class="hs-identifier hs-var">bytes</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679535993"><span class="hs-identifier hs-var">bbuf</span></a></span><span>
</span><span id="line-133"></span><span>  </span><span class="annot"><span class="annottext">(Int, Buffer Word8) -&gt; IO (Int, Buffer Word8)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679535990"><span class="hs-identifier hs-var">res</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Buffer Word8 -&gt; Buffer Word8
forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAdjustL"><span class="hs-identifier hs-var">bufferAdjustL</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679535993"><span class="hs-identifier hs-var">bbuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679535990"><span class="hs-identifier hs-var">res</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679535987"><span class="hs-identifier hs-var">bbuf'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-134"></span><span>
</span><span id="line-135"></span></pre></body></html>